package io.gitee.zicai.bus.listener;

import io.gitee.zicai.bus.adaptor.IBusSendAdaptor;
import io.gitee.zicai.bus.bus.ISendBus;
import io.gitee.zicai.bus.core.IBusSender;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * BaseBusSendListener
 *
 * @author zicai
 * @since 2021-01-20
 */
@Slf4j
public abstract class BaseBusSendListener<S extends IBusSender, SB extends ISendBus<S, ST>, ST> implements IBusSendListener<S, SB, ST> {

    public void cmdSendHandler(IBusSendAdaptor<S, SB, ST> cmdSendAdaptor, SB bus) {
        if (Objects.isNull(bus.getBiConsumer())) {
            log.warn(">>> There is no SendMethod for payload -> {}", bus.getSendParam());
            return;
        }
        cmdSendAdaptor.tryInvokeCmd().accept(bus);
    }
}
